package com.ovidiojf.timeTableGraph;

import java.util.Date;
import javax.swing.JLabel;
import com.ovidiojf.geneticAlgorithm.GeneticAlgorithm;

public class ShowTimeTable extends Thread{

    private volatile boolean allDone = false;
    
    public ShowTimeTable(boolean allDone) {
		super();
		this.allDone = allDone;
	}

	public boolean isAllDone() {
        return allDone;
    }

    public void setAllDone(boolean allDone) {
        this.allDone = allDone;
    }

    @Override
    public synchronized  void run() {

    	gen.setTimeOFirstGen(new Date().getTime());
    	int countDownToShow = 0;
    	
    	while(!allDone) {
    		
        	gen.doNewGeneration();

        	if (countDownToShow < 1) {       	
        		Show();
        		gen.doLog();
        		countDownToShow = 10;
        	}
        	
        	countDownToShow--;
        	timeTableBoard.setTxtInfo(gen.getInfo());
        	
        	if (gen.getBestFitness() == 0) 
        		allDone = true;
        
        }
		Show();
		gen.doLog();
		gen.ShowLog();
    }

    
    public void Show() {
    	timeTableBoard.setTable(gen.getTheBest());	
    	timeTableBoard.showGame();
    	
    	System.out.println("--> "+gen.getShortInfo());
    }
    
    public JLabel getLabel() {
        return label;
    }

    public void setLabel(JLabel label) {
        this.label = label;
    }
    
    
	public TimeTableBoard getTableBoard() {
		return timeTableBoard;
	}

	public void setTimeTableBoard(TimeTableBoard sb) {
		this.timeTableBoard = sb;
	}
    
    public GeneticAlgorithm getGen() {
		return gen;
	}

	public void setGen(GeneticAlgorithm gen) {
		this.gen = gen;
	}

	private TimeTableBoard timeTableBoard;
    private GeneticAlgorithm gen;
    private JLabel label;
	
}
